package cn.wolfcode.rbac.util;

import lombok.Getter;
import lombok.Setter;

import java.util.Collections;
import java.util.List;

/**
 *
 * Created by Administrator on 2020/7/13 0013.
 */
@Getter
@Setter
public class PageResult {
    public static final PageResult DEFAULT_DATA = new PageResult(1,5, Collections.emptyList(),0);


    private Integer currentPage; // 当前页
    private Integer pageSize;  // 每页显示的数据

    private List list ;  // 集合相关数据
    private Integer totalCount;  // 数据库中数据总条数

    private Integer totalPage;   //总页数
    private Integer prePage;   //上一页
    private Integer nextPage;  //下一页

    public PageResult(Integer currentPage, Integer pageSize, List list, Integer totalCount) {
        this.currentPage = currentPage;
        this.pageSize = pageSize;
        this.list = list;
        this.totalCount = totalCount;


        this.totalPage = this.totalCount % this.pageSize > 0 ? this.totalCount / this.pageSize + 1 : this.totalCount / this.pageSize;
        this.prePage = this.currentPage - 1 >= 1 ?  this.currentPage - 1  : 1;
        this.nextPage = this.currentPage + 1 <= totalPage ? this.currentPage + 1 : totalPage;
    }
}
